package com.example.yiwei.crm.view.activity.coordinationActivity;

import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.PopupMenu;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.base.BaseActivity;
import com.example.yiwei.crm.base.baseClass;
import com.example.yiwei.crm.data.GetDock;
import com.example.yiwei.crm.entity.activityEntity;
import com.example.yiwei.crm.entity.dockingEntity;
import com.example.yiwei.crm.entity.scheduleEntity;
import com.example.yiwei.crm.readcard.MainActivitycard;
import com.example.yiwei.crm.util.NetWorkUtils;
import com.example.yiwei.crm.view.activity.customerActivity.CustomerAddActivity;
import com.example.yiwei.crm.view.activity.healthActivity.addVisitActivity;
import com.example.yiwei.crm.view.frament.coordinationFrament.CoorBaseFrament;
import com.example.yiwei.crm.view.frament.coordinationFrament.CoorOtherBaseFragnent;
import com.example.yiwei.crm.view.frament.coordinationFrament.CoorOtherFragment;
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton;
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu;
import com.oguzdev.circularfloatingactionmenu.library.SubActionButton;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class DetailedCoordinationActivity extends BaseActivity implements View.OnClickListener{
    ImageView fabIconStar;
    FloatingActionMenu leftCenterMenu;
    //    FloatingActionMenu leftCenterMenu1;
    FloatingActionButton leftCenterButton;
    FloatingActionButton leftCenterButton1;
    private TextView txt_title;
    private ImageView img_back,img_update,img_more,img_call,img_message;
    int dock_id;
    boolean ButtonTag2 = false;
    boolean ButtonTag1 = false;
    boolean ButtonTag4 = false;
    FragmentManager manager;
    com.example.yiwei.crm.entity.dockingEntity docking;
    List<dockingEntity> dockingEntityList;
    List<dockingEntity>  dockinglist;
    private Button btn_base,btn_main,btn_other;
    Fragment fragment_base,fragment_main,fragment_other;
    dockingEntity dockingEntity;
    dockingEntity dockingEntity1;
    private TextView txt_visit_number,txt_referral_amount,txt_clinical_amount,txt_operation_amount,
            txt_giving_count;
    private PopupMenu popupMenu;
    private PopupMenu popupMenu1;
    String[] sex;
    AlertDialog.Builder builder;
    private Menu menu;
    private Menu menu1;
    boolean aBoolean=false;
    List<scheduleEntity> scheduleEntityList;
    List<com.example.yiwei.crm.entity.activityEntity> list;
    List<String> visit_list;
    private String visit_theme;
    private String[]themes;
    int number;
    private String[]activity_themes;
    private int visit_theme_id;
    scheduleEntity schedule;
    List<String> activity_list;
    String activity_theme;
    SharedPreferences sp;
    activityEntity activityEntity;
    String phone_number;
    private ImageView img_shouye,img_more1;
    String result;
    ImageView lcIcon1 ;
    ImageView lcIcon2 ;
    ImageView lcIcon3 ;
    ImageView lcIcon4 ;
    private PopupWindow mPopWindow;
    private TextView txt_attention;
    private ImageView img_attention;
    public static DetailedCoordinationActivity a;
    Intent intent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detailed_coordination);
        sp = getSharedPreferences("login", Context.MODE_PRIVATE);
        a=this;
        btn_base= (Button) findViewById(R.id.detailed_dock_frame_basemess);
        img_shouye= (ImageView) findViewById(R.id.simple_coording_img_shouye);
        img_more1= (ImageView) findViewById(R.id.simple_coording_img_more);
        btn_main= (Button) findViewById(R.id.detailed_dock_frame_main);
        img_call= (ImageView) findViewById(R.id.detailed_dock_img_call);
        img_message= (ImageView) findViewById(R.id.detailed_dock_img_message);
        btn_other= (Button) findViewById(R.id.detailed_dock_frame_other);
        img_back= (ImageView) findViewById(R.id.detailed_dock_img_back);
        img_update= (ImageView) findViewById(R.id.detailed_dock_img_update);
        txt_title= (TextView) findViewById(R.id.detailed_dock_txt_name);
        txt_visit_number= (TextView) findViewById(R.id.detailed_dock_txt_visit_number);
        txt_clinical_amount= (TextView) findViewById(R.id.detailed_dock_txt_clinical_amount);
        txt_referral_amount= (TextView) findViewById(R.id.detailed_dock_txt_referral_amount);
        txt_operation_amount= (TextView) findViewById(R.id.detailed_dock_txt_operation_amount);
        txt_giving_count= (TextView) findViewById(R.id.detailed_dock_txt_giving_count);
        txt_attention= (TextView) findViewById(R.id.detailed_dock_txt_attention);
        img_attention= (ImageView) findViewById(R.id.detailed_dock_img_attention);
        dockingEntity= GetDock.get();
        txt_title.setText(dockingEntity.getDocking_name());
        txt_visit_number.setText(dockingEntity.getVisit_number()+"");
        txt_clinical_amount.setText(dockingEntity.getClinical_amount()+"");
        txt_referral_amount.setText(dockingEntity.getReferral_amount()+"");
        txt_operation_amount.setText(dockingEntity.getOperation_amount()+"");
        txt_giving_count.setText(dockingEntity.getGiving_count()+"");
        if (dockingEntity.getIs_attention()==0){
            txt_attention.setText("未关注");
            img_attention.setImageResource(R.drawable.weiguanzhu1);
        }else if (dockingEntity.getIs_attention()==1) {
            txt_attention.setText("已关注");
            img_attention.setImageResource(R.drawable.yiguanzhu1);
        }
        dock_id=dockingEntity.getDocking_id();
        manager = getSupportFragmentManager();
        fragment_base=new CoorBaseFrament();
        fragment_main=new CoorOtherBaseFragnent();
        fragment_other=new CoorOtherFragment();
        OnClick(btn_base);
        popupMenu = new PopupMenu(this, findViewById(R.id.simple_coording_img_more));
        menu = popupMenu.getMenu();
        final MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_coord, menu);
        addXuanFu1();
        popupMenu1 = new PopupMenu(this, findViewById(R.id.detailed_dock_img_more));
        menu1 = popupMenu1.getMenu();
        final MenuInflater inflater1 = getMenuInflater();
        inflater1.inflate(R.menu.munu_coor1, menu1);
        popupMenu1.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    //删除
                    case R.id.coord_delete:
                        AlertDialog.Builder builder;
                        builder = new AlertDialog.Builder(new ContextThemeWrapper(DetailedCoordinationActivity.this, R.style.custom_dialog));
                        builder.setTitle("您确定要删除吗？");
                        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                new Thread(new Runnable() {
                                    @Override
                                    public void run() {
                                        JSONObject object = new JSONObject();
                                        try {
                                            object.put("DEL01", 1);
                                            object.put("KXA01", dock_id);
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                        String json = object.toString();
                                        result = NetWorkUtils.getCount(baseClass.delect_coordianation_URL, json);
                                        runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                try {
                                                    JSONObject object1 = new JSONObject(result);
                                                    boolean b = object1.getBoolean("ifsuccess");
                                                    if (b) {
                                                        finish();
                                                    }
                                                } catch (JSONException e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                        });
                                    }
                                }).start();
                            }
                        });
                        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {

                            }
                        });
                        builder.show();
                        break;
                }
                return false;
            }
        });
        //下拉框监听方法
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.customer_record:
                        Intent intent3 = new Intent(DetailedCoordinationActivity.this,CoorCustomerActivity.class);
                        intent3.putExtra("dockid",dock_id);
                        startActivity(intent3);
                        break;
                    case R.id.add_coord_record:
                        Intent intent4 = new Intent(DetailedCoordinationActivity.this,SimpleintmentActivity.class);
                        intent4.putExtra("id",dock_id);
                        startActivity(intent4);
                        break;
                    case R.id.appointment_record:
                        Intent intent=new Intent(DetailedCoordinationActivity.this,CoordingCommunicateActivity.class);
                        intent.putExtra("team_id",dock_id);
                        startActivity(intent);
                        break;
                    case R.id.coord_visit:
                        Intent intent2 = new Intent(DetailedCoordinationActivity.this,CoordinationVisitActivitu.class);
                        intent2.putExtra("dockid",dock_id);
                        startActivity(intent2);
                        break;
                    case R.id.gift_record:
                        Intent intent1 = new Intent(DetailedCoordinationActivity.this,CoordinationGiftActivity.class);
                        intent1.putExtra("dockid",dock_id);
                        startActivity(intent1);
                        break;
                    case R.id.operation_log:
                        Intent intent5 = new Intent(DetailedCoordinationActivity.this,OperationLogActivity.class);
                        intent5.putExtra("dockid",dock_id);
                        startActivity(intent5);
                        break;
                }
                return false;
            }
        });
        img_shouye.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
                SimpleCoordinationActivity.s.finish();
            }
        });
        img_more1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showPopupWindow();
            }
        });
        img_message.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                List<String> names = new ArrayList<String>();
                names.add(dockingEntity.getPhone_number());
                sex = names.toArray(new String[names.size()]);
                if (dockingEntity!=null){
                    showMessageDialog();
                }else{
                    Toast.makeText(DetailedCoordinationActivity.this, "无联系电话！", Toast.LENGTH_SHORT).show();
                }

            }
        });
        img_call.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                List<String> names = new ArrayList<String>();
                names.add(dockingEntity.getPhone_number());
                sex = names.toArray(new String[names.size()]);
                if (dockingEntity!=null){
                    showContactDialog();
                }else{
                    Toast.makeText(DetailedCoordinationActivity.this, "无联系电话！", Toast.LENGTH_SHORT).show();
                }

            }
        });
        img_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(DetailedCoordinationActivity.this,CoordinationAddActivity.class);
                intent.putExtra("tag","update");
                startActivity(intent);
            }
        });
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        finish();
                    }
                }).start();


            }
        });
        //悬浮按钮的监听
        leftCenterMenu.setStateChangeListener(new FloatingActionMenu.MenuStateChangeListener() {
            @Override
            public void onMenuOpened(FloatingActionMenu floatingActionMenu) {
                aBoolean=true;
                /*
                /构建两层按钮可使两个menu的点击按钮重合，当点击外层按钮用open方法使内层按钮展开，关闭同理
                 */
//                leftCenterMenu1.open(true);
                // 增加按钮中的+号图标顺时针旋转45度
//                // Rotate the icon of rightLowerButton 45 degrees clockwise
//                icon.setRotation(0);
//                PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 45);
//                ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(icon, pvhR);
//                animation.start();
                //按钮的初始角度
                fabIconStar.setRotation(0);
                //按钮的旋转角度
                PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 45);
                ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(fabIconStar, pvhR);
                animator.start();

            }

            @Override
            public void onMenuClosed(FloatingActionMenu floatingActionMenu) {
                aBoolean=false;
//                leftCenterMenu1.close(true);
                fabIconStar.setRotation(45);
                PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 0);
                ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(fabIconStar, pvhR);
                animator.start();
            }
        });
        lcIcon1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder builder;
                builder = new AlertDialog.Builder(new ContextThemeWrapper(DetailedCoordinationActivity.this,R.style.custom_dialog));
                builder.setTitle("请选择信息录入方式");
                builder.setPositiveButton("手动输入", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(DetailedCoordinationActivity.this, CustomerAddActivity.class);
                            intent.putExtra("dockid", dock_id);
                            intent.putExtra("TAG", "coor");
                            startActivity(intent);

                    }
                });
                builder.setNegativeButton("仪器扫描", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(DetailedCoordinationActivity.this, MainActivitycard.class);
                            intent.putExtra("dockid", dock_id);
                            intent.putExtra("TAG", "coor");
                            startActivity(intent);
                    }
                });
                builder.show();
            }
        });
        lcIcon2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1 = new Intent(DetailedCoordinationActivity.this, addVisitActivity.class);
                intent1.putExtra("docking_id", dock_id);
                intent1.putExtra("TAG", "coordination");
                startActivity(intent1);

            }
        });
        lcIcon3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(DetailedCoordinationActivity.this,CoordingAddCommunicationActivity.class);
                intent.putExtra("team_id1",dock_id);
                startActivity(intent);
            }
        });
       lcIcon4.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               Intent intent=new Intent(DetailedCoordinationActivity.this,CoorCustomerActivity.class);
               intent.putExtra("dockid",dock_id);
               startActivity(intent);
           }
       });

    }
    public void showMessageDialog(){
        //    设置一个单项选择下拉框
        /**
         * 第一个参数指定我们要显示的一组下拉单选框的数据集合
         * 第二个参数代表索引，指定默认哪一个单选框被勾选上，1表示默认'女' 会被勾选上
         * 第三个参数给每一个单选项绑定一个监听器
         */
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.custom_dialog));
        builder.setTitle("请选择联系人");
        builder.setSingleChoiceItems(this.sex, -1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                number=which;
                String name=sex[which];
                if (name.equals(dockingEntity.getPhone_number())){
                    phone_number=name;
                    if (name.equals("")){
                        Toast.makeText(DetailedCoordinationActivity.this, "无联系人电话！", Toast.LENGTH_SHORT).show();
                    }else{
                        messageDialog();
                    }
                    dialog.dismiss();
                }
            }
        });
        builder.show();
    }
    public void  messageDialog(){
        builder = new AlertDialog.Builder(new ContextThemeWrapper(DetailedCoordinationActivity.this, R.style.custom_dialog));
        builder.setTitle("您确定要发送短信吗？");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:"+phone_number));
                startActivity(intent);

            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        builder.show();
    }
    public void showContactDialog() {
        //    设置一个单项选择下拉框
        /**
         * 第一个参数指定我们要显示的一组下拉单选框的数据集合
         * 第二个参数代表索引，指定默认哪一个单选框被勾选上，1表示默认'女' 会被勾选上
         * 第三个参数给每一个单选项绑定一个监听器
         */
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.custom_dialog));
        builder.setTitle("请选择联系人");
        builder.setSingleChoiceItems(this.sex, -1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                number=which;
                String name=sex[which];
                if (name.equals(dockingEntity.getPhone_number())){
                    phone_number=name;
                    if (name.equals("")){
                        Toast.makeText(DetailedCoordinationActivity.this, "无联系人电话！", Toast.LENGTH_SHORT).show();
                    }else{
                        contactDialog();
                    }
                    dialog.dismiss();
                }
            }
        });
        builder.show();
    }
    public void contactDialog(){
        builder = new AlertDialog.Builder(new ContextThemeWrapper(DetailedCoordinationActivity.this, R.style.custom_dialog));
        builder.setTitle("您确定要拨打电话吗？");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Intent intent = new Intent(Intent.ACTION_DIAL);
                Uri data = Uri.parse("tel:" + phone_number);
                intent.setData(data);
                startActivity(intent);
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        builder.show();
    }
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            FloatingActionMenu v = leftCenterMenu;
            if (isShouldHideKeyboard(v, ev)) {
//                Toast.makeText(this, aBoolean+"", Toast.LENGTH_SHORT).show();
                if (leftCenterMenu.isOpen()){
                    leftCenterMenu.close(true);
                    aBoolean = false;
                }
            }
        }
        return super.dispatchTouchEvent(ev);
    }

    /**
     * 根据控件所在坐标和用户点击的坐标相对比，来判断是否隐藏，因为当用户点击控件时则不能隐藏
     *
     * @param v
     * @param event
     * @return
     */
    private boolean isShouldHideKeyboard(FloatingActionMenu v, MotionEvent event) {
        if (v != null ) {
            int[] l = {100, 100};
            int left = l[0],
                    top = l[1],
                    bottom = top ,
                    right = left ;
            if (event.getX() > left && event.getX() < right
                    && event.getY() > top && event.getY() < bottom) {
                // 点击控件的事件，忽略它。
                return false;
            } else {
                return true;
            }
        }
        // 如果焦点不是控件则忽略，这个发生在视图刚绘制完，第一个焦点不在EditText上，和用户用轨迹球选择其他的焦点
        return false;
    }


    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.detailed_dock_frame_other:
                ButtonTag2 = false;
                ButtonTag1 = true;
                ButtonTag4 = false;
                btn_other.setBackgroundColor(Color.parseColor("#FFFFFF"));
                btn_base.setBackgroundColor(Color.parseColor("#E1E8ED"));
                btn_main.setBackgroundColor(Color.parseColor("#E1E8ED"));
                manager.beginTransaction().replace(R.id.detailed_dock_frame_conner, fragment_other).commit();
                break;
            case R.id.detailed_dock_frame_basemess:
                ButtonTag1 = false;
                ButtonTag2 = true;
                ButtonTag4 = false;
                btn_other.setBackgroundColor(Color.parseColor("#E1E8ED"));
                btn_base.setBackgroundColor(Color.parseColor("#FFFFFF"));
                btn_main.setBackgroundColor(Color.parseColor("#E1E8ED"));
                manager.beginTransaction().replace(R.id.detailed_dock_frame_conner, fragment_base).commit();
                break;
            case R.id.detailed_dock_frame_main:
                ButtonTag1 = false;
                ButtonTag2 = false;
                ButtonTag4 = true;
                btn_other.setBackgroundColor(Color.parseColor("#E1E8ED"));
                btn_base.setBackgroundColor(Color.parseColor("#E1E8ED"));
                btn_main.setBackgroundColor(Color.parseColor("#FFFFFF"));
                manager.beginTransaction().replace(R.id.detailed_dock_frame_conner, fragment_main).commit();
                break;
            case R.id.detailed_dock_img_more:
                 intent = new Intent(DetailedCoordinationActivity.this,CoorDelectActivity.class);
                 intent.putExtra("id",dock_id);
                intent.putExtra("zt", dockingEntity.getIs_attention());
                startActivity(intent);
                break;

        }
    }
    public void  addXuanFu1(){
        /**
         * 一个FloatingActionButton有一个FloatingActionMenu，FloatingActionMenu添加动画弹出的子菜单。
         * FloatingActionButton的按钮点击事件将触发、弹出FloatingActionMenu中包含的子菜单。
         * FloatingActionMenu使用attachTo方法附着在一个FloatingActionButton上。
         * FloatingActionMenu在attachTo到一个FloatingActionButton后，两者之间发生关联。
         * FloatingActionMenu在添加子菜单时候，首先需要一个SubActionButton.Builder，该SubActionButton.
         * Builder通过setContentView(ImageView
         * image).build()把一个ImageView创建生产一个SubActionButton ,
         * 然后通过FloatingActionMenu.Builder的add方法把前面生成的SubActionButton添加进去。
         *
         *
         * 按钮的旋转动画在onMenuOpened和onMenuClosed中做。
         *
         */
        WindowManager wm = (WindowManager) getApplicationContext()
                .getSystemService(Context.WINDOW_SERVICE);

        int width = wm.getDefaultDisplay().getWidth();
        int height = wm.getDefaultDisplay().getHeight();
        //按钮的大小
        int redActionButtonSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_size1);
        //距离下边的长度
        int redActionButtonMargin = 7;
        //距离右边的长度
        int redActionButtonMarginRight = width/2-getResources().getDimensionPixelSize(R.dimen.red_action_button_content_size)/2;
        //按钮中内容的大小
        int redActionButtonContentSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_size);
        int redActionButtonContentMargin = getResources()
                .getDimensionPixelSize(R.dimen.red_action_button_content_margin);
        //弹出圆弧的半径
        int redActionMenuRadius = getResources().getDimensionPixelSize(R.dimen.red_action_menu_radius2);
        int blueSubActionButtonSize = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_size);
        int blueSubActionButtonContentMargin = getResources()
                .getDimensionPixelSize(R.dimen.blue_sub_action_button_content_margin);

        fabIconStar = new ImageView(this);
        //按钮中的图片
        fabIconStar.setImageDrawable(getResources().getDrawable(R.drawable.plus5));

        FloatingActionButton.LayoutParams starParams = new FloatingActionButton.LayoutParams(redActionButtonSize,
                redActionButtonSize);
        starParams.setMargins(redActionButtonMargin, redActionButtonMargin, redActionButtonMarginRight,
                redActionButtonMargin);
        fabIconStar.setLayoutParams(starParams);

        FloatingActionButton.LayoutParams fabIconStarParams = new FloatingActionButton.LayoutParams(
                redActionButtonContentSize, redActionButtonContentSize);
        fabIconStarParams.setMargins(redActionButtonContentMargin, redActionButtonContentMargin,
                redActionButtonContentMargin, redActionButtonContentMargin);

        leftCenterButton = new FloatingActionButton.Builder(this)
                .setContentView(fabIconStar, fabIconStarParams)
                .setBackgroundDrawable(R.drawable.button_action_red_selector)// 设置变化时的背景色
                .setPosition(FloatingActionButton.POSITION_BOTTOM_RIGHT)// 靠近右边和下边
                .setLayoutParams(starParams).build();

        // Set up customized SubActionButtons for the right center menu
        SubActionButton.Builder lCSubBuilder = new SubActionButton.Builder(this);
        lCSubBuilder.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_action_blue_selector));

        FrameLayout.LayoutParams blueContentParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.MATCH_PARENT);
        blueContentParams.setMargins(blueSubActionButtonContentMargin, blueSubActionButtonContentMargin,
                blueSubActionButtonContentMargin, blueSubActionButtonContentMargin);
        lCSubBuilder.setLayoutParams(blueContentParams);
        // Set custom layout params
        FrameLayout.LayoutParams blueParams = new FrameLayout.LayoutParams(blueSubActionButtonSize,
                blueSubActionButtonSize);
        lCSubBuilder.setLayoutParams(blueParams);

//        ImageView lcIcon1 = new ImageView(this);
//        ImageView lcIcon2 = new ImageView(this);
//        ImageView lcIcon3 = new ImageView(this);
//
//        lcIcon1.setImageDrawable(getResources().getDrawable(R.drawable.u116));
//        lcIcon2.setImageDrawable(getResources().getDrawable(R.drawable.u117));
//        lcIcon3.setImageDrawable(getResources().getDrawable(R.drawable.u118));
        //添加按钮
        lcIcon1 = new ImageView(this);
        lcIcon2 = new ImageView(this);
        lcIcon3 = new ImageView(this);
        lcIcon4 = new ImageView(this);

//         lcIcon4 = new TextView(this);
        lcIcon1.setImageDrawable(getResources().getDrawable(R.drawable.u1190));
        lcIcon2.setImageDrawable(getResources().getDrawable(R.drawable.u1193));
        lcIcon3.setImageDrawable(getResources().getDrawable(R.drawable.u1191));
        lcIcon4.setImageDrawable(getResources().getDrawable(R.drawable.u1192));
//        lcIcon4.setText("选择部门");

        // Build another menu with custom options
        leftCenterMenu = new FloatingActionMenu.Builder(this)
                .addSubActionView(lCSubBuilder.setContentView(lcIcon1, blueContentParams).build())
                .addSubActionView(lCSubBuilder.setContentView(lcIcon2, blueContentParams).build())
                .addSubActionView(lCSubBuilder.setContentView(lcIcon3, blueContentParams).build())
                .addSubActionView(lCSubBuilder.setContentView(lcIcon4, blueContentParams).build())
                .setRadius(redActionMenuRadius).setStartAngle(220).setEndAngle(320).attachTo(leftCenterButton).build();



    }
    protected void onRestart() {
        super.onRestart();
        dockingEntity=GetDock.get();
        txt_title.setText(dockingEntity.getDocking_name());
        if(ButtonTag2){
            fragment_base = new CoorBaseFrament();
            manager.beginTransaction().replace(R.id.detailed_dock_frame_conner,fragment_base).commitAllowingStateLoss();
        }else if (ButtonTag1){
            fragment_other = new CoorOtherFragment();
            manager.beginTransaction().replace(R.id.detailed_dock_frame_conner,fragment_other).commitAllowingStateLoss();
        }else if (ButtonTag4){
            fragment_main = new CoorOtherBaseFragnent();
            manager.beginTransaction().replace(R.id.detailed_dock_frame_conner,fragment_main).commitAllowingStateLoss();
        }
if (GetDock.dockingEntity!=null){
    if (GetDock.dockingEntity.getIs_attention()==0){
        txt_attention.setText("未关注");
        img_attention.setImageResource(R.drawable.weiguanzhu1);
    }else if (GetDock.dockingEntity.getIs_attention()==1) {
        txt_attention.setText("已关注");
        img_attention.setImageResource(R.drawable.yiguanzhu1);
    }
}

    }
    private void showPopupWindow() {
        View contentView = LayoutInflater.from(DetailedCoordinationActivity.this).inflate(
                R.layout.popowindow, null);

        mPopWindow = new PopupWindow(contentView);
        mPopWindow.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        mPopWindow.setHeight( LinearLayout.LayoutParams.WRAP_CONTENT);

        contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int popupWidth = contentView.getMeasuredWidth();    //  获取测量后的宽度
        int popupHeight = contentView.getMeasuredHeight();  //获取测量后的高度
        int[] location = new int[2];
        TextView tv1 = (TextView)contentView.findViewById(R.id.customer_record);
        TextView tv2 = (TextView)contentView.findViewById(R.id.add_coord_record);
        TextView tv3 = (TextView)contentView.findViewById(R.id.appointment_record);
        TextView tv4 = (TextView)contentView.findViewById(R.id.coord_visit);
        TextView tv5 = (TextView)contentView.findViewById(R.id.gift_record);
        TextView tv6 = (TextView)contentView.findViewById(R.id.operation_log);
        TextView tv7 = (TextView)contentView.findViewById(R.id.jl_log);
        tv7.setOnClickListener(this);
        tv1.setOnClickListener(this);
        tv2.setOnClickListener(this);
        tv3.setOnClickListener(this);
        tv4.setOnClickListener(this);
        tv5.setOnClickListener(this);
        tv6.setOnClickListener(this);

        img_more1.getLocationOnScreen(location);
        mPopWindow.setAnimationStyle(R.style.contextMenuAnim);
        mPopWindow.setBackgroundDrawable(getResources().getDrawable(
                R.drawable.pop_bg));
        mPopWindow.setTouchable(true);
        mPopWindow.setOutsideTouchable(true);   //设置外部点击关闭ppw窗口
        mPopWindow.setFocusable(true);
        mPopWindow.update();

        mPopWindow.showAtLocation(img_more1, Gravity.NO_GRAVITY, (location[0] + img_more1.getWidth() / 2) - popupWidth / 2, location[1] - img_more1.getHeight()/2-popupHeight);

    }
    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id){
            case R.id.customer_record:
                Intent intent3 = new Intent(DetailedCoordinationActivity.this,CoorCustomerActivity.class);
                intent3.putExtra("dockid",dock_id);
                startActivity(intent3);
                break;
            case R.id.add_coord_record:
                Intent intent4 = new Intent(DetailedCoordinationActivity.this,SimpleintmentActivity.class);
                intent4.putExtra("id",dock_id);
                startActivity(intent4);
                break;
            case R.id.appointment_record:
                Intent intent=new Intent(DetailedCoordinationActivity.this,CoordingCommunicateActivity.class);
                intent.putExtra("team_id",dock_id);
                startActivity(intent);
                break;
            case R.id.coord_visit:
                Intent intent2 = new Intent(DetailedCoordinationActivity.this,CoordinationVisitActivitu.class);
                intent2.putExtra("dockid",dock_id);
                startActivity(intent2);
                break;
            case R.id.gift_record:
                Intent intent1 = new Intent(DetailedCoordinationActivity.this,CoordinationGiftActivity.class);
                intent1.putExtra("dockid",dock_id);
                startActivity(intent1);
                break;
            case R.id.operation_log:
                Intent intent5 = new Intent(DetailedCoordinationActivity.this,OperationLogActivity.class);
                intent5.putExtra("dockid",dock_id);
                startActivity(intent5);
                break;
            case R.id.jl_log:
                Intent intent6 = new Intent(DetailedCoordinationActivity.this,SimpleJLActivity.class);
                intent6.putExtra("dockid",dock_id);
                startActivity(intent6);
                break;
        }

    }

}
